from pyspark import SparkConf, SparkContext

if __name__ == '__main__':
    # 构建SparkConf对象
    conf = SparkConf().setAppName("test").setMaster("local[*]")
    # 构建SparkContext执行环境入口对象
    sc = SparkContext(conf=conf)

    rdd = sc.parallelize(["a", "b", "c", "e", "d"])

    result = rdd.take(3)
    """
    take: 取出rdd前N个元素，组合成list返回
    """

    print(result)

    # 输出结果 ['a', 'b', 'c']